package com.ruoyi.web.controller.system;

import java.util.List;

import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Kaoqin;
import com.ruoyi.system.service.IKaoqinService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 考勤管理Controller
 * 
 * @author ruoyi
 * @date 2021-03-23
 */
@Controller
@RequestMapping("/system/kaoqin")
@Api(tags = "考勤管理")
public class KaoqinController extends BaseController
{
    private String prefix = "system/kaoqin";

    @Autowired
    private IKaoqinService kaoqinService;

    @RequiresPermissions("system:kaoqin:view")
    @GetMapping()
    public String kaoqin()
    {
        return prefix + "/kaoqin";
    }

    /**
     * 查询考勤管理列表
     */
    @RequiresPermissions("system:kaoqin:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Kaoqin kaoqin)
    {
        startPage();
        List<Kaoqin> list = kaoqinService.selectKaoqinList(kaoqin);
        return getDataTable(list);
    }

    /**
     * 导出考勤管理列表
     */
    @RequiresPermissions("system:kaoqin:export")
    @Log(title = "考勤管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Kaoqin kaoqin)
    {
        List<Kaoqin> list = kaoqinService.selectKaoqinList(kaoqin);
        ExcelUtil<Kaoqin> util = new ExcelUtil<Kaoqin>(Kaoqin.class);
        return util.exportExcel(list, "kaoqin");
    }

    /**
     * 新增考勤管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存考勤管理
     */
    @RequiresPermissions("system:kaoqin:add")
    @Log(title = "考勤管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Kaoqin kaoqin)
    {
        return toAjax(kaoqinService.insertKaoqin(kaoqin));
    }

    /**
     * 修改考勤管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Kaoqin kaoqin = kaoqinService.selectKaoqinById(id);
        mmap.put("kaoqin", kaoqin);
        return prefix + "/edit";
    }

    /**
     * 修改保存考勤管理
     */
    @RequiresPermissions("system:kaoqin:edit")
    @Log(title = "考勤管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Kaoqin kaoqin)
    {
        return toAjax(kaoqinService.updateKaoqin(kaoqin));
    }

    /**
     * 删除考勤管理
     */
    @RequiresPermissions("system:kaoqin:remove")
    @Log(title = "考勤管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(kaoqinService.deleteKaoqinByIds(ids));
    }
}
